'use strict';
//门店业绩
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import DatePicker from 'react-native-modal-datetime-picker'
import AchieveList from './achieveList';//业绩列表
import MyAchievement from './myAchievement';
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView
} from 'react-native';
export default class shopAchieve extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            shopList:null
        };
      }

    componentDidMount() {
        this.getShopList()
    }

      getShopList(){
          let url = URLconstant.SHOP_LIST_ACHIEVE
          let datakey=[]
          datakey['user_id']=this.props.user_id
          Util.get(url,datakey,this.getListSuc.bind(this),this.errorCallback.bind(this))
      }

    getListSuc(datas){
        if(datas.status==0){
            this.setState({
                shopList:datas.data
            })
        }else{
            this.setState({
                shopList:[]
            })
        }
    }
    errorCallback(err){

    }

    toAchieve(shop_id,shop_name){
          this.props.navigator.push({
              component:MyAchievement,
              passProps:{
                  allShop:1,
                  user_id:this.props.user_id,
                  shop_id:shop_id,
                  shop_name:shop_name
              }
          })
    }

      render(){
          let shopList = this.state.shopList
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '门店业绩',id:2}}/>
                  {
                      shopList==null?
                          <View style={{flex:1}}>
                              {Util.loading()}
                          </View>
                          :
                          <View style={{flex:1}}>
                              {
                                  shopList.length==0?
                                  <View style={{flex:1}}>
                                      <Text>没有门店数据</Text>
                                  </View>
                                  :
                                  <ScrollView style={{flex:1}}>
                                      {
                                          shopList.map((item,index)=>{
                                              return(
                                                  <TouchableOpacity onPress={()=>this.toAchieve(item.id,item.store_name)} key={index} style={styles.list_item}>
                                                      <Image
                                                          source={require('../../imgs/user.png')}
                                                          resizeMode={'cover'}
                                                          style={{width:50,height:50}}
                                                      />
                                                      <View style={styles.item_right}>
                                                          <Text style={{fontSize:16,color:"#333"}}>{item.store_name}</Text>
                                                          <View style={styles.item_bottom}>
                                                              <Text style={{fontSize:14,color:"#9e0a16"}}>今日业绩:¥{item.current_day_sale}</Text>
                                                              <Text style={{fontSize:14,color:"#9e0a16"}}>总业绩:¥{item.all_sale}</Text>
                                                          </View>
                                                      </View>
                                                      <Image
                                                          source={require('../../imgs/right_arrow.png')}
                                                          style={{width:25,height:25,marginLeft:10}}
                                                          resizeMode={'cover'}
                                                      />
                                                  </TouchableOpacity>
                                              )
                                          })
                                      }
                                  </ScrollView>
                              }
                          </View>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    list_item:{
        flexDirection:'row',
        padding:10,
        marginBottom:10,
        alignItems:'center',
        backgroundColor:"#fff"
    },
    item_right:{
        height:50,
        justifyContent:'space-between',
        flex:1,
        paddingHorizontal:10
    },
    item_bottom:{
        flex:1,
        justifyContent:'space-between',
        flexDirection:'row',
        alignItems:'flex-end'
    }
})